package com.aletto.general_store.ui.activities;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.aletto.general_store.R;
import com.aletto.general_store.utils.SoftKeyBoardUtils;
import com.aletto.general_store.utils.ToastUtils;
import com.aletto.general_store.utils.XHelper;
import com.sisyphus.spinach.utils.RichTextHelper;

/**
 * 意见反馈
 */
public class FeedbackActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        XHelper.initTitle(this, R.string.title_feedback);

        RadioGroup radio_group = findViewById(R.id.radio_group);
        TextView et_feedback = findViewById(R.id.et_feedback);
        TextView tv_feedback_tips = findViewById(R.id.tv_feedback_tips);
        tv_feedback_tips.setText(
                RichTextHelper.newBuilder(getString(R.string.feedback_tips))
                        .append(getString(R.string.feedback_service))
                        .foregroundColor(Color.parseColor("#ED5E62"))
                        .click(v -> ToastUtils.makeText("客服"))
                        .build()
        );

        // 键盘
        ScrollView scroll_view = findViewById(R.id.scroll_view);
        SoftKeyBoardUtils softKeyBoardUtils = new SoftKeyBoardUtils(this);
        softKeyBoardUtils.setOnSoftKeyBoardChangeListener((height, visibility) -> {
            if (visibility){
                scroll_view.fullScroll(View.FOCUS_DOWN);
            }
        });

        // 提交反馈
        findViewById(R.id.confirm_button).setOnClickListener(v -> {
            et_feedback.setText("");
            radio_group.clearCheck();
            ToastUtils.makeText(R.string.feedback_success);
            finish();
        });
    }

}
